import CommonUtils from "./common-utils.js"
import CRC from './crc.js'

export default {
	formatB2Cmd(deviceId, code, value, step) {
		var cmd = '5A';
		var verCode = '4D53130006'
		verCode += CommonUtils.str_pad("00000000", deviceId.toString(16));
		verCode += CommonUtils.str_pad("00", code.toString(16));
		verCode += CommonUtils.str_pad("00", parseInt(value / step).toString(16));
		cmd += verCode;
		cmd += CRC.ToCRC16(CommonUtils.str2Bytes(verCode));
		cmd += '4D';
		return cmd;
	},
	formatA1Cmd(deviceId, code, value) {
		var cmd = '5A';
		var verCode = '4D53150006'
		verCode += CommonUtils.str_pad("00000000", deviceId.toString(16));
		verCode += CommonUtils.str_pad("00", code.toString(16));
		verCode += CommonUtils.str_pad("00", value.toString(16));
		cmd += verCode;
		cmd += CRC.ToCRC16(CommonUtils.str2Bytes(verCode));
		cmd += '4D';
		return cmd;
	}
}
